package nx.simple3d.main;


import java.io.File;
import java.io.FileNotFoundException;

import javax.swing.UIManager;

import nx.simple3d.data.ObjFile;
import nx.simple3d.data.World;
import nx.simple3d.gui.Window;


public class Core {
 
  private World world;
  private Window window;
  private Engine engine;
  private static String[] ARGS;
  
  public static void main(String[] args) {
    Core.ARGS = args;
    new Core();
  }

  public Core(){
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    initialize();
  }
  
  private void initialize(){
    try {
      world = new World();
      for(String arg : ARGS){
        ObjFile objFile = new ObjFile(new File(arg));
        world.getMeshes().add(objFile.createMesh());
      }
      
      double[] cameraTrans = {-10, 0, 0};
      world.getCamera().getTransformation().rotateY(Math.PI / 180 * 90);
      world.getCamera().getTransformation().translate(cameraTrans);
      
      window = new Window(this);
      window.setVisible(true);
      
      engine = new Engine(this);
      engine.startEngine();
    }
    catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
  
  public World getWorld(){
    return world;
  }
  
  public Window getWindow(){
    return window;
  }
  
  public Engine getEngine(){
    return engine;
  }
}
